﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using DomainDriver.DomainModeling.Configuration;
using DomainDriver.DomainModeling.StorageManagers.EntityFrameworkStorage;
using AutomotivePricingModel.BodyStyles;
using AutomotivePricingModel.Brands;
using AutomotivePricingModel.Companies;
using AutomotivePricingModel.Countries;
using AutomotivePricingModel.Dealers;
using AutomotivePricingModel.DriveTrainTypes;
using AutomotivePricingModel.ProductionModels;
using AutomotivePricingModel.TransmissionTypes;
using AutomotivePricingModel.Vehicles;
using AutomotivePricingModel.ValueObjects.MissingValueOptions;
using AutomotivePricingModel.ValueObjects.YearlyFinancialAssessments;

namespace AutomotivePricingModel
{
    public class AutomotivePricingDatabaseContext : DbContext
    {
        private static string s_DefaultConnectionName = "AutomotivePricingModel.AutomotivePricingDatabaseContext";

        public static string DefaultConnectionName
        {
            get { return s_DefaultConnectionName; }
            set { s_DefaultConnectionName = value; }
        }

        static AutomotivePricingDatabaseContext()
        {
            string configValue = DomainDriverConfigurationHelper.ConnectionToUse;

            if (configValue != null)
            { DefaultConnectionName = configValue; }
        }

        public AutomotivePricingDatabaseContext()
            : this(DefaultConnectionName)
        { }

        public AutomotivePricingDatabaseContext(string nameOrConnectionString)
            : base(nameOrConnectionString)
        { }

        // DDD Aggregates/Entities
        public DbSet<BodyStyle> BodyStyles { get; set; }
        public DbSet<Brand> Brands { get; set; }
        public DbSet<Company> Companies { get; set; }
        public DbSet<Country> Countries { get; set; }
        public DbSet<Dealer> Dealers { get; set; }
        public DbSet<DealerBrandRelation> DealerBrandRelations { get; set; }
        public DbSet<DealerVehicleRelation> DealerVehicleRelations { get; set; }
        public DbSet<DriveTrainType> DriveTrainTypes { get; set; }
        public DbSet<ProductionModel> ProductionModels { get; set; }
        public DbSet<TransmissionType> TransmissionTypes { get; set; }
        public DbSet<Vehicle> Vehicles { get; set; }

        // DDD Value Objects
        public DbSet<MissingValueOption> MissingValueOptions { get; set; }
        public DbSet<YearlyFinancialAssessment> YearlyFinancialAssessments { get; set; }
        public DbSet<YearValueObservation> YearValueObservations { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            ForcedMappingUtilities.CreateForcedMappings(this, modelBuilder);
        }
    }
}